<template>
    <div>
        <div style="padding:3px 6px">
            <el-button size="mini" type="primary" @click="recallDevlieryPlan">重推移交</el-button>
            <el-button size="mini" type="primary" @click="recallInventory">重推台账</el-button>
            <el-button size="mini" type="primary" @click="reCallCoordinate">重推协调</el-button>
            <el-button size="mini" type="primary" @click="recallScanBack">重推扫码退回</el-button>
            <el-button size="mini" type="primary" @click="openDialog">修改质量编号</el-button>
            <el-button size="mini" type="primary" @click="updatedeliveryStatus">修改交接单状态</el-button>
            <el-button v-if="userJobNumber=='274099'" size="mini" type="primary" @click="reDeliveryStatus">修改交接单状态为已废除</el-button>
            <el-button size="mini" type="primary" @click="showMore">更多功能</el-button>
        </div>
        <div>
            <!--yebo 所有批量推送按钮移动到此处-->
            <el-dialog title="重推" :visible.sync="sendDialog.dialogVisible"  width="70%" :before-close="sendDialogHandleClose">
                <span>以下按钮功能均是根据配置表推送,配置表为ms_recall_tab</span>
                <div style="margin-top:3px;">
                    <el-button size="mini" type="primary"  @click="recallTabDevlieryPlan">推送移交</el-button>
                    <el-tag type="info">重推指定配置表移交信息到ERP,ms_recall_tab需要设置的字段是wms_delivery_paln_id</el-tag>
                </div>
                <div style="margin-top:3px">
                    <el-button size="mini" type="primary"  @click="recallTabInventory">推送台账</el-button>
                    <el-tag type="info">重推指定配置表台账信息到ERP,ms_recall_tab需要设置的字段是wms_delivery_paln_id</el-tag>
                </div>
                <div style="margin-top:3px">
                    <el-button size="mini" type="primary"  @click="recallTabInvOut">推送出库</el-button>
                    <el-tag type="info">重推指定配置表出库到ERP,ms_recall_tab需要设置的字段是wms_inv_out_allotment_id;wms_delivery_paln_id字段无所谓,可以为随机值</el-tag>
                </div>
                <div style="margin-top:3px">
                    <el-button size="mini" type="primary"  @click="recallTabAllot">推送占用</el-button>
                    <el-tag type="info">重推指定配置表占用到ERP,ms_recall_tab需要设置的字段是wms_inv_out_allotment_id;wms_delivery_paln_id字段无所谓,可以为随机值</el-tag>
                </div>
            </el-dialog>
            <!--修改交接单状态dialog-->
            <el-dialog title="质量编号修改" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
                <ul>
                    <li style="list-style: none;"><el-input placeholder="请输入修改后的质量编号" v-model="itemCode" ></el-input></li>
                    <li style="list-style: none;"><el-input placeholder="请输入密码" v-model="passwordValue" show-password></el-input></li>
                </ul>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false;passwordValue='';">取 消</el-button>
                    <el-button type="primary" @click="dialogVisible = false; updateQualityCode();passwordValue='';">确 定</el-button>
                </span>
            </el-dialog>
        </div>
        <el-table  ref="receiveTable" border :default-sort = "{prop:'startLotNo,endLotNo', order: 'descending'}" size="mini" :data="resData" style="width: 100%" highlight-current-row  @selection-change="handleSelectionChange" height="500" >
            <el-table-column type="selection" width="40"> </el-table-column>
            <el-table-column prop="ROW_ID" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryStatus" label="交接状态" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="attribute5Desc" label="交接单类型" width="120" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="aoNo" label="AO" width="120" :show-overflow-tooltip="true"> </el-table-column>

            <el-table-column prop="barcode" label="条码" width="150" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="mProductNumber" label="成品型号" width="120" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="itemCode" label="图号" width="160" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="qualityCode" label="质量编号" width="130" :show-overflow-tooltip="true"> </el-table-column>
            
            <el-table-column prop="itemName" label="物料名称" width="130" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryPlanCode" label="交接单号" width="160" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="bulkyLocator" label="大件库位号" width="160" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="attribute4Desc" label="标准件物料条码" width="160" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryQty" label="移交数量" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="storageQty" label="接收数量" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryEmpCode" label="移交人" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="requireShop" label="需求单位" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryShop" label="配送单位" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryDate" label="移交时间" width="120" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="receiveDate" label="接收时间" width="120" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="productCode" label="机型" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="batchNo" label="批次" width="50" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="startLotNo" label="起始架次" width="100" :show-overflow-tooltip="true" sortable> </el-table-column>
            <el-table-column prop="endLotNo" label="截止架次" width="100" :show-overflow-tooltip="true" sortable> </el-table-column>
            <el-table-column prop="mesCheckQualitificationId" width="160" label="合格证号" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="xProductCode" label="限用机型" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="xLimitBatchNo" label="限用批次" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="xLimitLotNo" label="限用架次" width="70" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="wmsDeliveryPlanId" label="交接单ID" width="170" :show-overflow-tooltip="true"> </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNumber"
        :page-sizes="[10,20,50,100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount">
        </el-pagination>
    </div>
</template>
<script>
import { mrMhAll } from "@/utils/api.js";
import request from "@/utils/request.js";
import TopInput from "./TopInput.vue";
export default {
    name:"ImHqTopTable",
    data(){
        return{
            itemCode:"",
            passwordValue:"",
            dialogVisible:false,
             // 当前页数
            pageNumber: 1,
            // 数据总个数
            totalCount: 0,
            // 返回的数据数组
            resData: [],
            // 每页数据个数
            pageSize: 20,
            // 确认列表高亮参数
            stableIndex: 0,
            selectedData:[],
            userJobNumber:'',
            sendDialog:{
                dialogVisible:false
            }
        }
    },
    methods:{
        handleClose(){
            this.passwordValue = "";
            this.itemCode = "";
            
        },
        sendDialogHandleClose(){
            this.sendDialog.dialogVisible = false;
        },
        openDialog(){
            this.dialogVisible = true;
        },
        showMore(){
            this.sendDialog.dialogVisible = true;
        },
        //修改交接单状态(作废改为已移交)
        updatedeliveryStatus(){
            if(this.selectedData.length==0){
                    this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                    return ;
                }else if (this.selectedData.length>1){
                    this.$Alert({title: "失败",message: '最多选择一条记录',type: "error"});
                    return ;
                }
                request.post("/DeliveryPlanQuery/updatedeliveryStatus",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                    if (res.data.code=='-1') {
                        this.$Alert({title: "失败",message: res.data.msg,type: "error"});
                    }else{
                        this.$Alert({title: "完成",message: res.data.msg,type: "success"});
                    }
                    //通过父组件调用兄弟组件方法，刷新列表
                    this.$emit("getList");
                })
        },
        //修改质量编号
         //重新推送台账信息到erp
        updateQualityCode(){
            //判断密码是否正确
            if(this.passwordValue=='147259'){
                if(this.selectedData.length==0){
                    this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                    return ;
                }else if (this.selectedData.length>1){
                    this.$Alert({title: "失败",message: '最多选择一条记录',type: "error"});
                    return ;
                }
                request.post("/DeliveryPlanQuery/updateQualityCode",{"datas":this.selectedData,"itemCode":this.itemCode,"type":"data"}).then((res)=>{
                    this.$Alert({title: "完成",message: res.data,type: "success"});
                    //通过父组件调用兄弟组件方法，刷新列表
                    this.$emit("getList");
                })
                
            }else{
                //提示密码输入错误
                this.$Alert({
                    title: "失败",
                    message: "密码错误！",
                    type: "error",
                });
            }
        },

            

        // 每页个数改变
        handleSizeChange(val){
            this.pageSize = val
            this.$bus.$emit('imHqPageSize',this.pageSize)
        },
        // 页数改变
        handleCurrentChange(val) {
            this.pageNumber = val;
            this.$bus.$emit('imHqPageNumber',this.pageNumber)
        },
        handleSelectionChange(val){
            this.selectedData = val;
        },
        //重新推送台账信息到erp
        recallInventory(){
            if(this.selectedData.length==0){
                this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                return ;
            }
            request.post("/TestCallWz/reCallToErp",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                this.$Alert({title: "完成",message: res.data,type: "success"});
            })
        },
        //重新推送交接单移交记录到erp
        recallDevlieryPlan(){
            if(this.selectedData.length==0){
                this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                return ;
            }
            request.post("/TestCallWz/reCallChangeTransfer",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                this.$Alert({title: "完成",message: res.data,type: "success"});
            })
        },
        //xiaojian 重推扫码退回记录到erp
        recallScanBack(){
            if(this.selectedData.length==0){
                this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                return ;
            }
            request.post("/TestCallWz/reCallScanBack",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                console.log("重推扫码退回记录",res);
                if(res.data.retCode == 200){
                    this.$Alert({title: "完成",message: res.data.alert,type: "success"});
                }
                else this.$Alert({title: "失败",message: res.data.alert,type: "error"});
            })
        },

        //xiaojian 重推协调记录到erp
        reCallCoordinate(){
            if(this.selectedData.length==0){
                this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                return ;
            }
            request.post("/TestCallWz/reCallCoordinate",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                console.log("重推协调记录",res);
                if(res.data.retCode == 200){
                    this.$Alert({title: "完成",message: res.data.alert,type: "success"});
                }
                else this.$Alert({title: "失败",message: res.data.alert,type: "error"});
            })
        },
        //重推移交
        recallTabDevlieryPlan(){ 
            request.post("/TestCallWz/reCallChangeTransfer",{"datas":[],"type":"table"}).then((res)=>{
                this.$Alert({title: "完成",message: res.data,type: "success"});
            })
        },
        //重推台账
        recallTabInventory(){
            request.post("/TestCallWz/reCallToErp",{"datas":[],"type":"table"}).then((res)=>{
                this.$Alert({title: "完成",message: res.data,type: "success"});
            })
        },
        //xiaojian 修改交接单状态为已废除
        reDeliveryStatus(){
            if(this.selectedData.length==0 || this.selectedData.length>1){
                this.$Alert({title: "失败",message: '请选择一条记录',type: "error"});
                return ;
            }
            request.post("/TestCallWz/updateDeliveryStatus",{"datas":this.selectedData,"type":"data"}).then((res)=>{
                console.log("修改交接单状态为已废除",res);
                if(res.data.retCode == 200){
                    this.$Alert({title: "完成",message: res.data.alert,type: "success"});
                    // 修改刷新Table并定位页数
                    this.$bus.$emit('sysSlRefreshTable','刷新');
                }
                else this.$Alert({title: "失败",message: res.data.alert,type: "error"});
                
            })
        },
        //重推出库
        recallTabInvOut(){//重新推送指定配置表出库
            request.get("/TestCallWz/makeMaterialCheck").then((res)=>{
                console.log("res",res);
                this.$Alert({title: "完成",message: res.data,type: "success"});
            });
        },
        //重推占用，推送指定配置表数据
        recallTabAllot(){
            request.get("/TestCallWz/sendOccupyInfo").then((res)=>{
                console.log("res",res);
                this.$Alert({title: "完成",message: res.data,type: "success"});
            });
        }

    },
    mounted() {
        // 接收TopInput查询到的数据
        this.$bus.$on('ImHqSearchData',(e)=>{
            this.resData = e.result
            this.totalCount = e.pageParameter.totalCount
            this.userJobNumber = window.sessionStorage.getItem("userJobNumber")
            console.log("session值",window.sessionStorage.getItem("userJobNumber"))
        })
  }
}
</script>
<style scoped>

</style>